import {useState, useEffect} from 'react'

export default function useRequest() {
  let [options, setOptions] = useState({currentPage: 1, pageSize: 10})
  let [data, setData] = useState({
    total: 0,
    pageCount: 0,
    list: []
  })

  // 请求数据
  function reqeust() {
    let {currentPage, pageSize} = options
    fetch(`http://localhost:8080/list?currentPage=${currentPage}&perSize=${pageSize}`)
      .then(res => res.json())
      .then(res => setData({...res}))
  }

  useEffect(reqeust, [options])

  return [data, options, setOptions]
}